﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using PGMHelper;

namespace WSAP
{
    /// <summary>
    /// 绘制单元内力曲线
    /// </summary>
    public partial class ElementForceForm : Form
    {
        /// <summary>
        /// 单元类型
        /// </summary>
        private WElementNet Element { set; get; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ElementForceForm(WElementNet element)
        {
            InitializeComponent();
            this.Element = element;
        }

        /// <summary>
        /// 选项改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RadioButtonCheckedChanged(object sender, EventArgs e)
        {
            this.RefreshChart((Control)sender);
        }

        /// <summary>
        /// 框架内力类型
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private FrameLocalForceEnum GetFrameLocalForceEnum(string name)
        {
            switch(name)
            {
                case "NRadioButton": return FrameLocalForceEnum.N;
                case "VyRadioButton": return FrameLocalForceEnum.Vy;
                case "VzRadioButton": return FrameLocalForceEnum.Vz;
                case "MyRadioButton": return FrameLocalForceEnum.My;
                case "MzRadioButton": return FrameLocalForceEnum.Mz;
                case "TRadioButton": return FrameLocalForceEnum.T;
                default: return FrameLocalForceEnum.N;
            }
        }

        /// <summary>
        /// 刷新绘图控件
        /// </summary>
        /// <param name="ctrl"></param>
        private void RefreshChart(Control ctrl)
        {
            //清空序列
            this.GraphChart.Series.Clear();
            //修改图名
            this.GraphChart.SetTitle(TiltleType.Header, ctrl.Text);
            //修改数据
            this.GridView.AddDatas(this.Element.GetData(this.GetFrameLocalForceEnum(ctrl.Name)));

            //绘图
            this.Element.SectionForceToChart(this.GraphChart,
                this.GetFrameLocalForceEnum(ctrl.Name));
        }

        /// <summary>
        /// 窗体显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ElementForceForm_Shown(object sender, EventArgs e)
        {
            this.Text = this.Element.GetTag().ToString();
            this.GridView.SetApperance(DataGridViewSelectionMode.FullColumnSelect);
            this.GraphChart.SetApperance(StringAlignment.Near, false, isLegendAvailabel: false);
            this.GraphChart.AddTitles("内力图", "距离系数", "内\n\n力");
            this.GraphChart.SetAxisFormat(ChartAxisType.AxisX, AxisFormat.Normal, 1);
            this.GraphChart.SetAxisFormat(ChartAxisType.AxisY, AxisFormat.Science, 2);
            this.GraphChart.SetAxisBroundary(ChartAxisType.AxisX, 0, 1);
            this.RefreshChart(this.MyRadioButton);
        }
    }
}
